package events.ui;

import java.text.ParseException;
import java.util.Date;

import ui.Command;
import ui.Dialog;
import util.UnexpectedException;
import events.Event;
import events.EventService;

public class EventCreator extends Command
{
	private Dialog dialog;
	private EventService eventService;
	
	@Override
	public boolean execute()
	{
		try
		{
			String title = dialog.ask("Title? ");
			Date date = dialog.askDate("Date? ");
			Event event = new Event();
			event.setTitle(title);
			event.setDate(date);
			eventService.store(event);
			return true;
		} catch (ParseException e)
		{
			throw new UnexpectedException(e);
		}
	}
	
	/**
	 * @return the dialog
	 */
	public Dialog getDialog()
	{
		return dialog;
	}

	/**
	 * @param dialog the dialog to set
	 */
	public void setDialog(Dialog dialog)
	{
		this.dialog = dialog;
	}

	/**
	 * @return the service
	 */
	public EventService getEventService()
	{
		return eventService;
	}

	/**
	 * @param service the service to set
	 */
	public void setEventService(EventService service)
	{
		this.eventService = service;
	}

}
